package function

import (
	"math/rand"
	"time"
)

type EmailFunction struct {
	size int
	data []interface{}
}

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

var emails = []string{
	"@gmail.com",
	"@yahoo.com",
	"@msn.com",
	"@hotmail.com",
	"@aol.com",
	"@ask.com",
	"@live.com",
	"@qq.com",
	"@0355.net",
	"@163.com",
	"@163.net",
	"@263.net",
	"@3721.net",
	"@yeah.net",
	"@googlemail.com",
	"@mail.com",
	"@hotmail.com",
	"@msn.com",
	"@yahoo.com",
	"@gmail.com",
	"@aim.com",
	"@aol.com",
	"@mail.com",
	"@walla.com",
	"@inbox.com",
	"@126.com",
	"@163.com",
	"@sina.com",
	"@21cn.com",
	"@sohu.com",
	"@yahoo.com.cn",
	"@tom.com",
	"@qq.com",
	"@etang.com",
	"@eyou.com",
	"@56.com",
	"@x.cn",
	"@chinaren.com",
	"@sogou.com",
	"@citiz.com",
	"@aol.com",
	"@netzero.net",
	"@twcny.rr.com",
	"@comcast.net",
	"@warwick.net",
	"@comcast.net",
	"@cs.com",
	"@verizon.net",
	"@vsnl.com",
	"@wilnetonline.net",
	"@cal3.vsnl.net",
}

func DefaultEmail(size int) *EmailFunction {
	return &EmailFunction{
		size: size,
		data: make([]interface{}, 0, size),
	}
}

func (e *EmailFunction) Build() []interface{} {
	rand.Seed(time.Now().Unix())
	for i := 0; i < e.size; i++ {
		e.data = append(e.data, e.randStr(rand.Intn(10)+5)+emails[rand.Intn(len(emails))])
	}
	return e.data
}

func (e *EmailFunction) randStr(n int) string {
	rand.Seed(time.Now().Unix())
	b := make([]rune, n)
	for i := range b {
		b[i] = letterRunes[rand.Intn(len(letterRunes))]
	}
	return string(b)
}
